package com.ruoyi.web.controller.golang;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IncomeLog;
import com.ruoyi.system.service.IIncomeLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户收入Controller
 * 
 * @author ruoyi
 * @date 2025-01-12
 */
@Controller
@RequestMapping("/system/log")
public class IncomeLogController extends BaseController
{
    private String prefix = "system/log";

    @Autowired
    private IIncomeLogService incomeLogService;

    @RequiresPermissions("system:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询用户收入列表
     */
    @RequiresPermissions("system:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IncomeLog incomeLog)
    {
        startPage();
        List<IncomeLog> list = incomeLogService.selectIncomeLogList(incomeLog);
        return getDataTable(list);
    }

    /**
     * 导出用户收入列表
     */
    @RequiresPermissions("system:log:export")
    @Log(title = "用户收入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IncomeLog incomeLog)
    {
        List<IncomeLog> list = incomeLogService.selectIncomeLogList(incomeLog);
        ExcelUtil<IncomeLog> util = new ExcelUtil<IncomeLog>(IncomeLog.class);
        return util.exportExcel(list, "用户收入数据");
    }

    /**
     * 新增用户收入
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户收入
     */
    @RequiresPermissions("system:log:add")
    @Log(title = "用户收入", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IncomeLog incomeLog)
    {
        return toAjax(incomeLogService.insertIncomeLog(incomeLog));
    }

    /**
     * 修改用户收入
     */
    @RequiresPermissions("system:log:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        IncomeLog incomeLog = incomeLogService.selectIncomeLogById(id);
        mmap.put("incomeLog", incomeLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户收入
     */
    @RequiresPermissions("system:log:edit")
    @Log(title = "用户收入", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IncomeLog incomeLog)
    {
        return toAjax(incomeLogService.updateIncomeLog(incomeLog));
    }

    /**
     * 删除用户收入
     */
    @RequiresPermissions("system:log:remove")
    @Log(title = "用户收入", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(incomeLogService.deleteIncomeLogByIds(ids));
    }
}
